// pages/insurance/insurance.js
import config from "../../../config.js";
const openIdUrl = config;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    search:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.loadData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  loadData: function() {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })

    wx.request({
      url: openIdUrl.customList,
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': wx.getStorageSync("session")
      },
      data: {
        start: 0,
        size: 10000,
        search: that.data.search
      },
      success: function(res) {
        console.log(res);
        wx.hideLoading();
        if (res.data.status == 200) {
          console.log(res.data.data);
          that.setData({
            list: res.data.data
          })

        } else {
          wx.hideLoading();
          wx.showToast({
            title: res.data.message + "",
            icon: 'none',
            mask: true,
            duration: 2000
          })
        }

      }
    })
  },
  chooseAction: function(e) {
    var item = e.currentTarget.dataset.item;
    // console.log(item);
    wx.setStorageSync("userchoose", item);
    // console.log(wx.getStorageSync("userchoose"));
    wx.navigateBack({
      delta: 1
    })

    wx.setStorageSync("carchoose", null);
  },

  bindTel: function(e) {
    var value = e.detail.value
    console.log(value);
    this.setData({
      search: value
    })
    this.loadData();
  },
  searchAction:function(e){
    var search=this.data.search;
    if (search!=""){
      this.loadData();
    }
  }
})